package com.boyinet.demo.pipelineleakage.scheduler;

import com.boyinet.demo.pipelineleakage.bean.primary.SchedulerJob;
import com.boyinet.demo.pipelineleakage.common.Constant;
import com.boyinet.demo.pipelineleakage.repository.primary.SchedulerJobRepository;
import com.boyinet.demo.pipelineleakage.service.LeakageService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.util.Date;

@Component
@Slf4j
public class CalcTrigger {

    final LeakageService leakageService;

    final SchedulerJobRepository schedulerJobRepository;

    public CalcTrigger(LeakageService leakageService, SchedulerJobRepository schedulerJobRepository) {
        this.leakageService = leakageService;
        this.schedulerJobRepository = schedulerJobRepository;
    }

    public void trigger(String group, String name) {
        SchedulerJob job = schedulerJobRepository.findSchedulerJobByJobGroupAndJobName(group, name);
        if (null != job) {
            SimpleDateFormat dateFormat = new SimpleDateFormat(Constant.DATE_TIME_FORMAT);
            //leakageService.load(job.getPipeLineId(), dateFormat.format(new Date()));
            log.info("{} run at {}", job.getContent(), dateFormat.format(new Date()));
        }
    }
}
